package com.gxl.design.filterpattern.impl;

import com.gxl.design.filterpattern.Car;
import com.gxl.design.filterpattern.Criteria;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

/**
 * @remark --
 * @author: GuoXiaolin
 * @date 2019/4/19 11:09
 * @Version 1.0
 * @Derction
 */
public class OrCriteria implements Criteria {

    private Criteria firstCriteria;
    private Criteria secondCriteria;
    private Criteria thirdCriteria;

    public OrCriteria(Criteria firstCriteria, Criteria secondCriteria, Criteria thirdCriteria) {
        this.firstCriteria = firstCriteria;
        this.secondCriteria = secondCriteria;
        this.thirdCriteria = thirdCriteria;
    }

    @Override
    public List<Car> meetCriteria(List<Car> carList) {
        List<Car> one = firstCriteria.meetCriteria(carList);
        List<Car> two = secondCriteria.meetCriteria(carList);
        List<Car> three = thirdCriteria.meetCriteria(carList);

        List<Car> listAll = new ArrayList<Car>();
        listAll.addAll(one);
        listAll.addAll(two);
        listAll.addAll(three);
        listAll = new ArrayList<Car>(new LinkedHashSet<>(listAll));

        return listAll;
    }
}
